package com.iqiju.guagua.redtone.video.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableSwaggerBootstrapUi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Profile("!prod")
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUi
public class Knife4jConfig {

    @Value("${knife4j-api.base-package}")
    private String basePackage;

    @Value("${knife4j-api.title}")
    private String title;

    @Value("${knife4j-api.description}")
    private String description;

    @Value("${knife4j-api.author}")
    private String author;

    @Value("${knife4j-api.email}")
    private String email;

    @Value("${knife4j-api.version}")
    private String version;

    @Bean
    public Docket createRestApi() {
        return  new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();

    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .contact(new Contact(author,null, email))
                .version(version)
                .build();
    }

}
